-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor StorageImpl #123
Refactor StorageImpl #123
Conversation
- PoolWrapper is passed as an external dependency - Postgres initialization code is moved into PgConnectionInit class - Corresponding fixes in Application and tests Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some points in my comments may be discussed, so I neither approve, nor demand changes.
|
||
FailoverCallback::FailoverCallback( | ||
soci::session &connection, | ||
std::function<void(soci::session &)> init, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why have you removed the original using InitFunctionType
?
|
||
namespace iroha { | ||
namespace ametsuchi { | ||
class FailoverCallbackFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the factory name is quite misleading. Factories tend to facilitate objects creation, while this one just passes all the arguments to the object's constructor.
What this class does is lifetime management.
Thus i would suggest renaming this class to something like FailoverCallbacksManager
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for renaming it into FailoverCallbackHolder
, I like your variant better than my ...Manager
. There are some more substitutions to be made though:
|
||
#include <memory> | ||
|
||
#include <soci/soci.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this include be avoided using a forward declaration, like you did for FailoverCallbackFactory
?
log_manager_(std::move(log_manager)), | ||
log_(log_manager_->getLogger()), | ||
pool_size_(pool_size), | ||
prepared_blocks_enabled_(enable_prepared_blocks), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the enable_prepared_blocks
constructor argument seems duplicating a field of pool_wrapper
:
prepared_blocks_enabled_(enable_prepared_blocks), | |
prepared_blocks_enabled_(pool_wrapper_->enable_prepared_transactions_), |
|
||
void StorageImpl::tryRollback(soci::session &session) { | ||
if (block_is_prepared_) { | ||
PgConnectionInit::rollbackPrepared(session, prepared_block_name_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks weird...
do you have a TODO to separate schema manager from connection initializer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Do we already have a task for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am strongly for creating one. Schema management should be separated from connection initialization and generic storage impl.
@@ -0,0 +1,11 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What did you add this file for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't. This is pretty annoying, some test modifies this file. I will fix it one day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it wasn't in .gitignore
for some reason so easy fix is coming.
} | ||
|
||
inline void processPqNotice(void *arg, const char *message) { | ||
auto *log = reinterpret_cast<logger::Logger *>(arg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you use logger::Logger
, you should include logger/logger.hpp
.
But I would suggest to move this to cpp file and to ensure that it has this include, because otherwise the CMake logger
target dependency must be manually added to every file using this header.
If you choose to follow my advise, please include #include "logger/logger_fwd.hpp"
to this file.
irohad/main/CMakeLists.txt
Outdated
target_link_libraries(pg_connection_init | ||
SOCI::postgresql | ||
SOCI::core | ||
fmt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt | |
logger |
The real dependency is logger
, and the fact that it compiles without it is a lucky chance.
#include "ametsuchi/reconnection_strategy.hpp" | ||
#include "common/result.hpp" | ||
#include "interfaces/permissions.hpp" | ||
#include "logger/logger_manager.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include "logger/logger_manager.hpp" | |
#include "logger/logger_manager_fwd.hpp" |
- Fixes in naming - Log dependencies - Couple of other small fixes Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
.gitignore
Outdated
@@ -31,8 +31,8 @@ include/generated/* | |||
iroha.conf | |||
peers.list | |||
cmake-build* | |||
test/system/irohad_test_data/config.sample.copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is in the repo and hence is versioned with other source. I think for your purposes you should use .git/info/exclude
, which is your private and does not synchronize.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ssssssssssss! I had to check this.
But anyway, it looks like a bad test design.
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall, thank you! However, some issues have to be addressed before the merge.
irohad/main/application.cpp
Outdated
@@ -175,13 +177,17 @@ void Irohad::dropStorage() { | |||
storage->reset(); | |||
} | |||
|
|||
// Irohad::RunResult Irohad::initPoolWrapper() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove commented-out code.
irohad/main/application.hpp
Outdated
@@ -152,6 +154,8 @@ class Irohad { | |||
protected: | |||
// -----------------------| component initialization |------------------------ | |||
|
|||
// virtual RunResult initPoolWrapper(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for commented-out code.
@@ -45,6 +47,8 @@ class StorageInitTest : public ::testing::Test { | |||
std::string pg_opt_without_dbname_; | |||
std::string pgopt_; | |||
|
|||
// std::shared_ptr<iroha::ametsuchi::PoolWrapper> pool_wrapper_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for commented-out code.
#include <soci/postgresql/soci-postgresql.h> | ||
|
||
#include "ametsuchi/reconnection_strategy.hpp" | ||
#include "failover_callback.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like self-include, please remove.
namespace ametsuchi { | ||
class PgConnectionInit { | ||
public: | ||
static std::string formatPostgresMessage(const char *message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be used only in pg_connection_init.cpp
, maybe move it there in an anonymous namespace? Same for processPqNotice
ReconnectionStrategyFactory &reconnection_strategy_factory, | ||
const PostgresOptions &options, | ||
logger::LoggerManagerTreePtr log_manager) { | ||
const int pool_size = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to make it a parameter as it was before, and define this variable in Irohad::initStorage
|
||
auto conn = initPostgresConnection(options_str, pool_size); | ||
if (auto e = boost::get<expected::Error<std::string>>(&conn)) { | ||
return expected::makeError(std::move(e->error)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return expected::makeError(std::move(e->error)); | |
return *e; |
irohad/main/application.hpp
Outdated
@@ -25,6 +25,8 @@ namespace iroha { | |||
class WsvRestorer; | |||
class TxPresenceCache; | |||
class Storage; | |||
class ReconnectionStrategyFactory; | |||
struct PoolWrapper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReconnectionStrategyFactory
still has to stay.
@@ -50,13 +51,42 @@ namespace iroha { | |||
std::make_unique<InMemoryBlockStorageFactory>(); | |||
auto reconnection_strategy_factory = std::make_unique< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this variable be made fixture static field? Otherwise its lifetime is not managed.
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
…ncremental updates to our proc macros Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
…ncremental updates to our proc macros Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Fix/dependencies
Description of the Change
StorageImpl refactoring:
Benefits
Connections could be created outside the storage now which is very convenient for testing and (coming) PostgresBlockStorage.
Possible Drawbacks
Pull request is huge :(